package com.xue.maper;

import com.xue.entity.Dept;
import com.xue.entity.Person;
import org.springframework.data.neo4j.annotation.Query;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface DeptRepository extends Neo4jRepository<Dept, Long> {

    @Query("MATCH (e:dept)-[r:relationShip]->(e1) where e.deptName=$deptName return e1")
    List<Dept> selectListByDeptName(@Param("deptName") String deptName);

    @Query("MATCH (ee:dept) WHERE ee.deptName = '技术部'\n" +
            "CREATE (js:dept { deptName: $deptName}),\n" +
            "(ee)-[:relationShip]->(js) return js")
    Dept createDept(@Param("deptName") String deptName);

    @Query("match (e:dept) where e.deptName=$deptName create (p:person {name:$name}),(e)-[:relationShip]->(p) return p")
    Person createPerson(String deptName, String name);
}
